feat: add data export, account deactivation, and deletion lifecycle API with cooling-off, anonymization, and audited idempotent jobs - #105
Merged
Conversation
…PI with cooling-off, anonymization, and audited idempotent jobs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issue
Closes #88
Summary
Implements the Data Export, Deactivation and Deletion API (API Roadmap Phase 1)
as a new privacy/account-lifecycle domain at
/api/v1/account.POST /exportexistingRequestId)GET /export/:idGET /export/:id/downloadPOST /deactivatePOST /reactivatePOST /deletionscheduledFor= now + cooling-off (default 30d)GET /deletionPOST /deletion/cancelReactivate/cancel are public-with-credentials because deactivation and deletion
requests revoke sessions and block login, a JWT-gated endpoint would be
unreachable. Both use
authLimiterand neutral 401s to prevent account-stateenumeration.
Deletion/anonymization matrix
Applied by the finalization job in a single transaction (all operations
idempotent, safe to re-run):
deleted+<id>@anon.invalid, random unloginable password, wallet nulled, statusDELETED) — preserves FK integrity for retained recordsJobs & concurrency
exponential backoff, dead-letter at max attempts).
updateMany;count === 0means another runner won concurrent sweeps and crashre-runs are safe. Cancel-vs-finalize races resolve the same way.
export/deletion request per user.
endpoints, optionally on
LIFECYCLE_SWEEP_INTERVAL_MS, andsweep()isexported for the future
WORKER_SCRIPT.Known limitation
JWTs are stateless: tokens issued before deactivation remain valid (up to
JWT_EXPIRES_IN, 1d) on routes that don't yet userequireActiveAccount.This PR applies it to the mutating lifecycle endpoints; adopting it across the
other v1 routers is a recommended follow-up.
Verification evidence
scoping, duplicate requests, unique-index races, claim races, expiry/410,
job failure → backoff → dead-letter, cancel-after-finalize.
tests/data-export.service.test.tsasserts thegenerated artifact contains no
password,token,tokenHash, orrefreshTokenfields; sessions export metadata only.tests/account-lifecycle.service.test.tsasserts every matrix row — hard-deletes issued for all PII tables, no
deletes for retained financial/on-chain tables, audit-log scrub payload,
and the exact tombstone shape of the user update.
tsc,prisma validate, and the Swagger spec (all 7 paths + newcomponent schemas) verified.
Screenshot